package cn.wolfcode.service;

import cn.wolfcode.domain.AccountLog;
import cn.wolfcode.domain.OperateIntergralVo;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.apache.ibatis.annotations.Param;

/**
 * 表明该服务是分支事务
 */
@LocalTCC
public interface IUsableIntegralService {

    /**
     * 用户减积分操作
     * @param vo
     */
    int descIntergral(OperateIntergralVo vo);

    /**
     * 用户增加积分
     * @param vo
     */
    int incrIntergral(OperateIntergralVo vo);

    /**
     * 用户增加积分 => try 操作
     * @param operateIntergralVo
     */
    @TwoPhaseBusinessAction(name = "incrIntergralTry",
    commitMethod = "incrInergralCommit",rollbackMethod = "incrIntergralRollback")
    void incrIntergralTry(
            @BusinessActionContextParameter(paramName = "operateIntergralVo") OperateIntergralVo operateIntergralVo,
                          BusinessActionContext context);

    /**
     * TCC的confirm方法
     * @param context
     */
    void incrInergralCommit(BusinessActionContext context);

    /**
     * TCC的 Canel 方法
     * @param context
     */
    void incrIntergralRollback(BusinessActionContext context);

    @TwoPhaseBusinessAction(name = "descIntergralTry",commitMethod = "descIntergralCommit",
    rollbackMethod = "descTntergralRollback")
    void descIntergralTry(@BusinessActionContextParameter(paramName = "operateIntergralVo") OperateIntergralVo
                                  operateIntergralVo,BusinessActionContext context);
    void descIntergralCommit(BusinessActionContext context);
    void descTntergralRollback(BusinessActionContext context);

}
